//
//  MainViewController.swift
//  微博
//
//  Created by mac on 15/12/12.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    let mainTabbar = MainTabbar()
    //addBtn的响应方法
     @objc private func addBtnClick() {
        print(__FUNCTION__)
       presentViewController(UINavigationController(rootViewController: SendBookViewController()), animated: true, completion: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //创建自定义的tabbar
        //设置addButton的响应事件
        mainTabbar.addButton.addTarget(self, action: "addBtnClick", forControlEvents: .TouchUpInside)
        //使用KVC赋值
        setValue(mainTabbar, forKey: "tabBar")
        addChildViewControllers()
    }
//创建4个界面
    func addChildViewControllers() {
        //设置选中的颜色,为系统的背景色
        tabBar.tintColor = UIColor.orangeColor()
        //创建基本的4哥tabbar控制器
        addChildController(HomeViewController(), title:"首页", imageName:"tabbar_home")
        addChildController(MessageViewController(), title:"消息", imageName:"tabbar_message_center")
        addChildController(DiscoverViewController(), title:"发现", imageName:"tabbar_discover")
        addChildController(ProfileViewController(), title:"我", imageName:"tabbar_profile")
//        addChildController("首页", imageName: "tabbar_home")
//        addChildController("消息", imageName: "tabbar_message_center")
//        addChildController("发现", imageName: "tabbar_discover")
//        addChildController("我的", imageName: "tabbar_profile")
//        
    }
    //创建tabbar控制器
    func addChildController(vc:UIViewController, title:String , imageName:String) {
        //创建一个navigationController
        let nvc = BaseNavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named:imageName)
        addChildViewController(nvc)
        
    }
    

}
